﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CNDM.UserControls.Menu
{
    public partial class ucLeftMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dt = new DataTable();
            dt = BO.Category.CategoryData.Get_Category(0);
            repMenuParent.DataSource = dt;
            repMenuParent.DataBind();
        }

        protected void repMenuParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            string linkFormat = "<a class='parent' href='{0}'>{1}</a>";
            int cat_child = 0;
            DataTable dtChild = new DataTable();
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal ltrCatParent = (Literal)e.Item.FindControl("ltrCatParent");
                ltrCatParent.Text = String.Format(linkFormat, DataBinder.Eval(e.Item.DataItem, "Cat_Url").ToString(), DataBinder.Eval(e.Item.DataItem, "Cat_Name").ToString());

                Repeater repMenuChild = (Repeater)e.Item.FindControl("repMenuChild");
                cat_child = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Cat_ID").ToString());
                dtChild = BO.Category.CategoryData.Get_Category(cat_child);
                repMenuChild.DataSource = dtChild;
                repMenuChild.DataBind();
            }
        }
    }
}